unit con_Contabilista;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Formulario_Padrao_Consulta, TFlatButtonUnit, StdCtrls, Buttons,
  ExtCtrls, Grids, DBGrids, DB, DBTables;

type
  TfrmCon_Contabilista = class(TFrmConsulta)
    dbgRepresentante: TDBGrid;
    edtNome: TEdit;
    Label1: TLabel;
    procedure BtnFecharClick(Sender: TObject);
    procedure edtNomeKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormActivate(Sender: TObject);
  private
    { Private declarations }
    procedure FazConsulta;
  public
    { Public declarations }
    CTB_Codigo: string;
  end;

var
  frmCon_Contabilista: TfrmCon_Contabilista;
  tds: Tdatasource;
  tq: Tquery;

implementation

uses Dm, clsContabilista;

var
  Contabilista: TCONTABILISTA;

{$R *.dfm}

procedure TfrmCon_Contabilista.BtnFecharClick(Sender: TObject);
begin
  inherited;
  CTB_codigo := tq.fieldbyname('Cont_Codigo').asstring;
  tds.free;
  tq.free;
end;

procedure TfrmCon_Contabilista.FazConsulta;
begin
  if edtnome.text = '' then
    edtnome.text := ' ';
  Contabilista := TContabilista.Create;
  Contabilista.Consultar(tq, edtnome.text);
  tq.open;
  Contabilista.free;
  dbgRepresentante.DataSource := tds;
  dbgRepresentante.Refresh;
end;

procedure TfrmCon_Contabilista.edtNomeKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  inherited;
  if key = 12 then begin
    FazConsulta;
    edtNome.setfocus;
  end;
end;

procedure TfrmCon_Contabilista.FormActivate(Sender: TObject);
begin
  inherited;
  tds := TDataSource.create(self);
  tq := Tquery.create(self);
  tq.databasename := dmint.db.databasename;
  tq.active := False;
  tds.DataSet := tq;
  fazconsulta;
  edtnome.setfocus;
end;

end.

